<?php
/**
 * 后台首页类
 */
namespace app\admin\controller;
use app\admin\controller\Common;
use think\Db;
class Index extends Common{

	/**
	 * 展示后台首页
	 */
	public function index(){

		return view();

	}

	/**
	 * 展示顶端
	 */
	public function top(){

		return view();

	}

	/**
	 * 展示左侧菜单
	 */
	public function menu(){

		$uid = session('id');

		if( $uid==1 ){

			$auths = db('auth')->where('auth_level','<',2)->order('sort,aid asc')->select();

		}else{

			//根据用户id取得用户角色id
			$roles = db('admin_role')->value('rid');
			
			//获取权限信息
			$where = ['auth_level'=>['lt',2],'r.rid'=>['in',$roles]];
			$auths = db('role as r')->join('jd_role_auth ra ','r.rid = ra.rid',"LEFT")->join('jd_auth a','ra.aid = a.aid','LEFT')->where($where)->order('sort,a.aid asc')->select();
		}

		$auths = getChildren($auths,'aid','parent_id',0);
		
		//分配变量
		$this->assign('auths',$auths);
		
		//展示视图
		return view();

	}

	/**
	 * 展示右侧主要区域
	 */
	public function main(){

		// mysql版本
		$mv = Db::query("select version() as mv");
		
		// 分配变量
		$this->assign('ps',PHP_OS);
		$this->assign('sa',$_SERVER["SERVER_ADDR"]);
		$this->assign('ss',$_SERVER["SERVER_SOFTWARE"]);
		$this->assign('pv',PHP_VERSION);
		$this->assign('mv',$mv[0]["mv"]);
		$this->assign('is',ini_get('safe_mode'));

		return view();

	}

}